package com.example.auth.validator;

import cn.hutool.core.util.IdcardUtil;
import com.example.auth.annotation.IDCard;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IdCardValidator implements ConstraintValidator<IDCard,String> {
    @Override
    public boolean isValid(String idcard, ConstraintValidatorContext context) {
        if (StringUtils.isBlank(idcard)) return true;
        return IdcardUtil.isValidCard(idcard);
    }
}
